﻿<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Import Namespace="Loushang.SSO4NET.Utils"%>

<%
    //throw new Exception("找不到登录服务！");
    string userId = Request["saml.userid"];
    string redirectUrl = Request["RelayState"];

    if (!string.IsNullOrEmpty(userId))
    {
        //Common.Log.LogManage.addLogErr(userId, redirectUrl);

        Business.Admin.StUserOperation userOperation = new Business.Admin.StUserOperation();
        System.Data.DataTable dtOut = userOperation.GetUserInfoByLoginName(userId);

        if (dtOut.Rows.Count > 0)//登陆成功
        {
            //Common.Log.LogManage.addLogErr(userId, "成功");

            System.Data.DataRow dr = dtOut.Rows[0];

            Business.Admin.StUserGroupHandle userGroup = new Business.Admin.StUserGroupHandle();
            string gid = userGroup.GetGroupId(dr["userid"].ToString());

            HttpContext.Current.Session.Clear();
            HttpContext.Current.Session.Add("UserId", dr["userid"]);
            HttpContext.Current.Session.Add("UserName", dr["user_name"]);
            HttpContext.Current.Session.Add("RealUserId", userId);
            HttpContext.Current.Session.Add("Password", dr["password"]);
            HttpContext.Current.Session.Add("GroupId", gid);

            //SessionLoginUtil.sessionLogin(this.Context, userId, Request["saml.sessionIndex"]);  //处理会话，保存会话映射
            SessionLoginUtil.sessionLogin(this.Context, userId);  //处理会话，保存会话映射
            //参数说明：第一个参数页面的httpContext；第二个参数request中的saml.userid参数，用户的id；第三个参数为门户系统的会话编号。

            Response.Redirect(redirectUrl); //页面重定向       
            //Response.Redirect("../frmMainNew.aspx");
        }
    }
    
%>
<html>
<head id="Head1" runat="server">
</head>
<body>
    <table width="50%" align="center" border="0">
        <tr>
            <td>
                <font size="4" color="red">用户不存在！ </font>
            </td>
        </tr>
    </table>
</body>
</html>
